/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.max.oti.system.bean.admin;

import com.max.oti.system.model.State;
import com.max.oti.system.model.TypeComission;
import com.max.oti.system.model.TypeUser;
import com.max.oti.system.model.User;
import com.max.oti.system.service.interfac.IStateService;
import com.max.oti.system.service.interfac.ITypeComissionService;
import com.max.oti.system.service.interfac.ITypeUserService;
import com.max.oti.system.service.interfac.IUserService;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author max
 */
@ManagedBean
@ViewScoped
public class MaesterDataBean {

   
    @ManagedProperty("#{stateService}")
    private IStateService stateService;
    @ManagedProperty("#{typeComissionService}")
    private ITypeComissionService typeComissionService;
    @ManagedProperty("#{typeUserService}")
    private ITypeUserService typeUserService;
    @ManagedProperty("#{userService}")
    private IUserService userService;
    private List<Object[]> listConfirm;
    private List<State> listStateInsert;
    private boolean isComplete = false;

    @PostConstruct
    public void verifiData() {
        try {
            listConfirm = stateService.listHQL("select s.name, s.nameEntity from State s where"
                    + " s.name='INACTIVO' and s.nameEntity='User'");

            if (listConfirm.isEmpty()) {
                isComplete = false;
            } else {
                isComplete = true;
            }
        } catch (Exception ex) {
            Logger.getLogger(MaesterDataBean.class.getName()).log(Level.SEVERE, null, ex);
        }




    }

    public void generateMaesterDataDevelopment() {
        try {
            if (!isComplete) {
                listStateInsert = new ArrayList<State>();
                listStateInsert.add(new State("inactivo", "User", "Usuario no se puede logear."));

                listStateInsert.add(new State("cumple", "AlumnRequirement", "Estado de un requerimiento de alumno querimiento de un alumno"));
                listStateInsert.add(new State("no cumple", "AlumnRequirement", "El alumno no cumple con su requerimiento"));

                listStateInsert.add(new State("cumple", "Menber1", "-"));
                listStateInsert.add(new State("no cumple", "Menber1", "-"));
                listStateInsert.add(new State("comisión", "Menber1", "-"));
                listStateInsert.add(new State("modificado", "Menber1", "-"));
                listStateInsert.add(new State("ratificado", "Menber1", "-"));

                listStateInsert.add(new State("anulado", "HistoryPractice", "-"));
                listStateInsert.add(new State("aprovado", "HistoryPractice", "-"));
                listStateInsert.add(new State("desaprovado", "HistoryPractice", "-"));
                listStateInsert.add(new State("supervisado", "HistoryPractice", "-"));
                listStateInsert.add(new State("iniciado", "HistoryPractice", "-"));

                for (int i = 0; i < listStateInsert.size(); i++) {
                    stateService.save(listStateInsert.get(i));
                }

                Integer idTCsgt = typeComissionService.save(new TypeComission("Comisión de Grados y Titulos"));
                Integer idTCsppp = typeComissionService.save(new TypeComission("Comisión de Practicas Pre Profesionales"));
//
                Integer idTUcom = typeUserService.save(new TypeUser("Comisión", "Gestiona los documentos de los alumnos"));
                typeUserService.save(new TypeUser("Alumno", "Revisa como va sus documentos"));

                User us = new User();
                us.setDniPerson("11111111");
                Integer idUser = (Integer) stateService.listHQL("select s.id from State s where "
                        + "s.name='ACTIVO' and s.nameEntity='User'", 0, 1).get(0);
                us.setIdState(new State(idUser));
                us.setIdTypeComission(new TypeComission(idTCsgt));
                us.setIdTypeUser(new TypeUser(idTUcom));
                us.setNick("sgt");
                us.setPassword("sgt");

                userService.save(us);
                User us2 = new User();
                us2.setIdState(new State(idUser));
                us2.setIdTypeUser(new TypeUser(idTUcom));
                us2.setDniPerson("22222222");
                us2.setIdTypeComission(new TypeComission(idTCsppp));
                us2.setNick("sppp");
                us2.setPassword("sppp");
                userService.save(us2);

                isComplete = true;
            } else {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void generateMaesterDataProduction() {

    }

    public boolean isIsComplete() {
        return isComplete;
    }

    public void setStateService(IStateService stateService) {
        this.stateService = stateService;
    }

    public void setTypeComissionService(ITypeComissionService typeComissionService) {
        this.typeComissionService = typeComissionService;
    }

    public void setTypeUserService(ITypeUserService typeUserService) {
        this.typeUserService = typeUserService;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }
}
